
var  katex = require("../katex-0.13.18/katex.js");
//gitbaytest.hi();
//console.log('gitbaykatex', gitbaykatex);

function test_katex_multi_line( ){
  var options = {"displayMode":true,"leqno":false,"fleqn":false,"throwOnError":true,"errorColor":"#cc0000","strict":"warn","output":"htmlAndMathml","trust":false,"macros":{"\\f":"#1f(#2)"}};
  //var tex ="\\int f(x) dx ";
  var tex = '\\mathcal{E}( t)  = t^4 \\cdot   \\Big(  F(X(t))  -F(X^\\ast) \\Big) ' +
    '+   \\Big\\|    t\\cdot      \\dot X(t) +4  \\cdot X(t)  -4 \\cdot X^\\ast\\Big\\|_2^2 ,\\newline ' +
    '\\frac{d^2X(t)}{dt^2} + \\frac{5}{t} \\frac{dX(t)}{dt} + t^2/2 \\cdot  \\nabla F(X ) = 0 '  ;
  var output = katex.renderToString(tex, options  );
  console.log('测试页面options : ',options );
  console.log('测试页面tex : ' , tex  );
  console.log('测试页面output : ',  output );
}

function test_tex_v0(){
  console.log('\n\n\n==============\n') ;
  console.log('latex 测试调用😃') ;
  
  var options = {"displayMode":true,"leqno":false,"fleqn":false,"throwOnError":true,"errorColor":"#cc0000","strict":"warn","output":"htmlAndMathml","trust":false,"macros":{"\\f":"#1f(#2)"}};
  //var tex ="\\int f(x) dx ";
  var tex = '\\mathcal{E}( t)  = t^4 \\cdot   \\Big(  F(X(t))  -F(X^\\ast) \\Big) ' +
    '+   \\Big\\|    t\\cdot      \\dot X(t) +4  \\cdot X(t)  -4 \\cdot X^\\ast\\Big\\|_2^2 ,\\newline ' +
    '\\frac{d^2X(t)}{dt^2} + \\frac{5}{t} \\frac{dX(t)}{dt} + t^2/2 \\cdot  \\nabla F(X ) = 0 '  ;
  //var output = katex.renderToString(tex, options  );
  console.log('测试页面options : ',options );
  console.log('测试页面tex : ' , tex  );
  
  
  var output = katex.renderToString(tex, options  );
 
  console.log('测试页面output : ',  output );
  
  
  console.log('==============\n\n\n\n') ;
  return output ;
}


function test_tex(){
  console.log('\n\n\n==============\n') ;
  console.log('latex 测试调用😃') ;
  
  var options = {"displayMode":true,"leqno":false,"fleqn":false,"throwOnError":true,"errorColor":"#cc0000","strict":"warn","output":"htmlAndMathml","trust":false,"macros":{"\\f":"#1f(#2)"}};
  //var tex ="\\int f(x) dx ";
  var tex =     '\n' +
        '\\mathcal{E}( t)  = t^4 \\cdot   \\Big(  F(\\lambda(t))  -F(\\lambda^\\ast) \\Big)\n' +
        '+   \\Big\\|    t\\cdot      \\dot \\lambda(t) +4  \\cdot \\lambda(t)  -4 \\cdot \\lambda^\\ast\\Big\\|_2^2 ,\\\\\n' +
        '\\frac{d^2\\lambda(t)}{dt^2} + \\frac{5}{t} \\frac{d\\lambda(t)}{dt} + t^2/2 \\cdot  \\nabla F(\\lambda ) = 0\n'     ;
  
  //var output = katex.renderToString(tex, options  );
  console.log('测试页面options : ',options );
  console.log('测试页面tex : ' , tex  );
  
  
  var output = katex.renderToString(tex, options  );
 
  console.log('测试页面output : ',  output );
  
  
  console.log('==============\n\n\n\n') ;
  return output ;
}

function tex_lines_to_html(lines ){
  var tex  = lines.join('//') ;
  var options = {"displayMode":true,"leqno":false,"fleqn":false,"throwOnError":true,"errorColor":"#cc0000","strict":"warn","output":"htmlAndMathml","trust":false,"macros":{"\\f":"#1f(#2)"}};
  //var tex ="\\int f(x) dx ";
  /*
  var tex = '\\mathcal{E}( t)  = t^4 \\cdot   \\Big(  F(X(t))  -F(X^\\ast) \\Big) ' +
    '+   \\Big\\|    t\\cdot      \\dot X(t) +4  \\cdot X(t)  -4 \\cdot X^\\ast\\Big\\|_2^2 ,\\newline ' +
    '\\frac{d^2X(t)}{dt^2} + \\frac{5}{t} \\frac{dX(t)}{dt} + t^2/2 \\cdot  \\nabla F(X ) = 0 '  ;
    */
  //var output = katex.renderToString(tex, options  );
  //console.log('测试页面options : ',options );
  console.log('测试页面tex : ' , tex  );
  
  
  var output = katex.renderToString(tex, options  );
  return output ;
  
}


function tex2html(tex ){
   
  var options = {"displayMode":true,
  //"leqno":false,
  //"fleqn":false,
  "throwOnError":true,
  "errorColor":"#cc0000",
  "strict":"warn","output":"htmlAndMathml",
  "trust":false,
  //"macros":{"\\f":"#1f(#2)"}
};
/**
var options = {"displayMode":true,"leqno":false,
"fleqn":false,"throwOnError":true,
"errorColor":"#cc0000","strict":"warn","output":"htmlAndMathml",
"trust":false,
"macros":{"\\f":"#1f(#2)"}
};
*/
  //var tex ="\\int f(x) dx ";
  /*
  var tex = '\\mathcal{E}( t)  = t^4 \\cdot   \\Big(  F(X(t))  -F(X^\\ast) \\Big) ' +
    '+   \\Big\\|    t\\cdot      \\dot X(t) +4  \\cdot X(t)  -4 \\cdot X^\\ast\\Big\\|_2^2 ,\\newline ' +
    '\\frac{d^2X(t)}{dt^2} + \\frac{5}{t} \\frac{dX(t)}{dt} + t^2/2 \\cdot  \\nabla F(X ) = 0 '  ;
    */
  //var output = katex.renderToString(tex, options  );
  //console.log('测试页面options : ',options );
  console.log('测试页面tex : ' , tex  );
  
  
  var output = katex.renderToString(tex, options  );
  return output ;
  
}


function hifun(){ 
  console.log('\n\n\n==============\n') ;
  console.log('hi \(^o^)/~ 测试调用😃') ;
  console.log('==============\n\n\n\n') ;
}


module.exports = {
    tex_lines_to_html: tex_lines_to_html, 
    tex2html: tex2html,
    test_tex: test_tex, 
    hi: hifun
};
